import BaseGroup from '@/components/js/BaseGroup'
import { EventBus } from '@/store/index'
import { COMPONENT_TYPES } from '@/common/const-wb'
import { createApp } from 'vue'
import ParticleCon from '@/components/dynamic/particle-con.vue'

export default class ParticleCartoon extends BaseGroup {
  constructor() {
    super();
    //子类覆盖
    // {"imgWidth":87,"imgCount":38",jsonUrl":"https://static.hd.xxx.com/upload/biz/1/silverRain.json"}
    this.particle = null;
    this.className = "particle";
    this.config = null;
  }

  start() {
    this.particle = this.item.interactionData.injectJsClassObj.particle
    window.axios.get(this.particle.jsonUrl)
    .then((response) => {
      this.config = response.data;
      this.createParticle(); 
    }).catch(function (error) {//请求失败处理
      console.log(error)
    })
    EventBus.$on("stopTick", this.onStopTick);
  }
  createParticle() {
    this.initFilterComponents(COMPONENT_TYPES.wb_img);
    let url = this.filterComponents[0].commonAttr.url;
    
    let comp = createApp(ParticleCon);
    comp.mount("#" + this.item.id);

    EventBus.$emit('particleData', { particle: this.particle, url: url, config: this.config });
  }

  destroy() {
    super.destroy();
    this.particle = null;
    this.className = "";
  }
}
